package com.gpnu.service;

import com.gpnu.mapper.CourseOrderMapper;
import com.gpnu.pojo.CourseOrder;
import com.gpnu.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseOrderServiceImpl implements CourseOrderService {

    @Autowired
    CourseOrderMapper orderMapper;

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {

        PageResult<CourseOrder> result = new PageResult<CourseOrder>();
        result.setCode(0);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("start", (page - 1) * pageSize);
        params.put("limit", pageSize);


        //获取总的记录数
        int totalCount = orderMapper.findCountByMap(params);
        result.setCount(totalCount);

        //获取查询的数据
        List<CourseOrder> list = orderMapper.findListByMap(params);

        result.setData(list);

        return result;
    }

    @Override
    public void save(CourseOrder order) {
        orderMapper.insert(order);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return orderMapper.findByOrderId(order_id);
    }

    @Override
    public CourseOrder deleteByOrderId(String order_id) {
        orderMapper.deleteByOrderId(order_id);
        return null;
    }
}
